/**
 * 项目名：admin
 * 包名：com.xuebang.admin.mapper
 * 文件名：ArticleMapper.java
 * 版本信息：@version 1.0
 * 日期：2014-1-17-下午2:06:29
 */
package com.xuebang.admin.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import com.xuebang.admin.entity.NewsTitle;

/**
 * 项目名称：admin
 * 类名称：ArticleMapper
 * 类描述：
 * 创建人：xuyang
 * 创建时间：2014-1-17 下午2:06:30
 * 修改人：xuyang
 * 修改时间：2014-1-17 下午2:06:30
 * 修改备注：
 * @version 
 */
public interface TitleMapper extends BaseMapper<NewsTitle> {
	
	
	/**
	 * 查询所有的新闻信息
	 * 
	 * @param intNewsLimit 每页限定的新闻条数
	 */
	@Select("select * from news_title where red=0 limit #{intNewsLimit}")
	List<NewsTitle> getNewsInfo(int intNewsLimit);

	/**
	 * 获得指定title的新闻
	 *
	 * @param title
	 * @param intCid
	 */
	@Select("select id from news_title where red=0 and title=#{title} and cid=#{intCid}")
	Integer findByTitle(@Param("title") String title,@Param("intCid") Integer intCid);
	
	/**
	 * 获得指定title的新闻
	 *
	 * @param title
	 */
	@Select("select id from news_title where red=0 and title=#{title} and cid is null")
	Integer findByTitleNoCol(String title);
	
	/**
	 * 增加新闻title
	 */
	@Insert("insert into news_title (title,author,cid,cname,copyfrom,ispic,picurl,edituser,description,ifelite,posttime,new_type,red,pages,pv) VALUES "+
			"(#{title},#{author},#{cid},#{cname},#{copyfrom},#{ispic},#{picurl},#{edituser},#{description},#{ifelite},#{posttime},0,0,#{pages},#{pv})")
	@SelectKey(statement = "select last_insert_id()", keyProperty = "id", before = false, resultType = Integer.class)
	void addNewsTitle(NewsTitle newsTitle);
	
	/**
	 * 修改新闻title
	 */
	@Update("update news_title set title=#{title},author=#{author},copyfrom=#{copyfrom},ispic=#{ispic},pv=#{pv}," +
			"picurl=#{picurl},edituser=#{edituser},description=#{description},ifelite=#{ifelite},cid=#{cid},cname=#{cname},posttime=#{posttime}" +
			" where id=#{id}")
	void updateNewsTitle(NewsTitle newsTitle);
	
	/**
	 * 增加
	 */
	@Select("select * from news_title where id=#{id}")
	NewsTitle findNews(Integer intId);
	
	/**
	 * 删除新闻
	 */
	@Delete("delete from news_title where id=#{id}")
	void deleteNewsTitle(NewsTitle newsTitle);
	
	/**
	 * 放入回收站
	 */
	@Update("update news_title set red=1 where id not in (18,19,20,21,27,29,30,31,32,33,34,39,40,41,42,43,44,45,51,52,53) and id = #{strArticleIDs}")
	void putIntoRecycleBin(String strArticleIDs);
	
	/**
	 * 放入回收站
	 */
	@Update("update news_title set red=0 where id = #{strArticleIDs}")
	void restore(String strArticleIDs);
	
	/**
	 * 搜索新闻
	 */
	@Select("select * from news_title where red=0 and title like #{searchText} limit #{intPageNo},#{intPageLimit}")
	List<NewsTitle> search(@Param("searchText") String searchText,
			@Param("intPageNo") int intPageNo,@Param("intPageLimit") int intPageLimit);
	
	/**
	 * 置顶
	 */
	@Update("update news_title set iftop=#{iftop} where id = #{id}")
	void makeTop(@Param("id")Integer id,@Param("iftop")Integer iftop);
	
	/**
	 * 推荐
	 */
	@Update("update news_title set ifelite=#{recommend} where id = #{id}")
	void recommend(@Param("id")Integer id,@Param("recommend")Integer recommend);
	
	/**
	 * 查找回收站中的所有文章
	 */
	@Select(" select * from news_title where red=1")
	List<NewsTitle> findAllDeletedNews();
}
